<template>
    <div>
  
       
             
                
          
       
        <input type="text" v-model="puar.bh">编号
       <input type="text" v-model="puar.mc">名称
        <input type="button" value="查询" @click="xs">


           
        <table>
            <thead>
                <tr>
                    <td>编号</td>
                    <td>名称</td>
                    <td>楼层</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="m in data"> 
                    <td>{{m.bh}}</td>
                    <td>{{m.mc}}
                        <img :src="'https://localhost:7219/'+m.mc" style="width: 100px; height: 100px;" >
                    </td>
                    <td>{{m.louc}}</td>
                    <td>
        <input type="button" value="删除" @click="sc(m.id)">
        <input type="button" value="修改" @click="xg(m.id)">

                    </td>
                </tr>
            </tbody>
        </table>
        <input type="button" value="首页" @click="page(1)">
        <input type="button" value="上一页" @click="page(2)">
        <input type="button" value="下一页" @click="page(3)">
        <input type="button" value="尾页" @click="page(4)">

    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { couldStartTrivia } from 'typescript';
import { ref,onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';

const rets = useRouter()
const data=ref([{
    "id": 0,
  "bh": "",
  "mc": "",
  "louc": ""
}])
const page=(w:any)=>{
    if(w==1){
        puar.value.index=1; 
        xs();
    }
    if(w==2){
        puar.value.index-=1;
        xs(); 
    }
    if(w==3){
        puar.value.index+=1; 
        xs();
    }
    if(w==4){
        puar.value.index=wes.value.plist;
        xs(); 
    }
}

onMounted(()=>{
    xs();
})

const puar=ref({
    index:1,
    page:3,
  bh: "",
  mc: "",

})
const wes=ref({
    count:0,
    plist:0,

})

const xs=()=>{
    axios.get("https://localhost:7219/api/we/xs",{params:puar.value}).then(res=>{
         data.value=res.data.plist


         wes.value.count=res.data.count
         wes.value.plist = Math.ceil( wes.value.count/puar.value.page)


    })
}
const tre=ref({
    "id":2 ,

})
const sc=(val:any)=>{
    if(!confirm("确认删除吗?"))
    {
        return;
    }
    debugger
    axios.delete("https://localhost:7219/api/we/delete",{params:{id:val}}).then(res=>{
        alert("删除成功");
        xs()
    })
}
const xg=(w:any)=>{
    rets.push({path:"/xg",query:{id:w}})
}

</script>

<style scoped>

</style>